package cc.booku.owlbox.SearchPage;

import android.content.Intent;
import android.graphics.Color;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

import com.czp.searchmlist.mSearchLayout;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cc.booku.owlbox.ArtDesign.SystemUtil;
import cc.booku.owlbox.Idiom.IdiomActivity;
import cc.booku.owlbox.R;
import cc.booku.owlbox.UnNavDataPage.NavDataActivity;

public class SearchActivity extends AppCompatActivity {


    //测试搜索：http://localhost:2020/search.php?searchdata=
    private mSearchLayout SearchView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
//状态栏颜色
        SystemUtil.setStatusBarColor(this, Color.parseColor("#448aca"));
        SearchView = (mSearchLayout) findViewById(com.czp.searchmlist.R.id.msearchlayout);
        initData();
    }

    protected void initData() {


        //历史记录
        String shareData = "古董局中局,天龙八部,永远的君主,唐人街探案3,剑雨,我不是药神,误杀";
        List<String> skills = Arrays.asList(shareData.split(","));

        //大家都在搜
        String shareHotData = "传闻中的陈芊芊,亲爱的义祁君,成语接龙,山寨小萌主,秋蝉,清平乐,韫色过浓";
        List<String> skillHots = Arrays.asList(shareHotData.split(","));

        SearchView.initData(skills, skillHots, new mSearchLayout.setSearchCallBackListener() {
            @Override
            public void Search(String str) {
                //进行或联网搜索
                //读取配置文件中的搜索接口

                if (str.equals("成语接龙")) {

                    //跳转到新页面
                    Intent intent = new Intent();
                    intent.setClass(SearchActivity.this, IdiomActivity.class);
                    startActivity(intent);

                } else if (str.equals("嘀嘀嘀") | str.equals("滴滴滴") | str.equals("dididi") | str.equals("2.14") | str.equals("11.11") | str.equals("污污污") | str.equals("wuwuwu")) {
                    Intent intent = new Intent();
                    intent.setClass(SearchActivity.this, NavDataActivity.class);
                    startActivity(intent);
                } else {

                    try {

                        //刷新
                        Intent intent = new Intent();
                        Bundle bundle = new Bundle();
                        bundle.putString("SearchData", str);
                        intent.putExtras(bundle);
                        intent.setClass(SearchActivity.this, SearchListActivity.class);
                        startActivity(intent);

                    } catch (Exception e) {

                        Toast.makeText(SearchActivity.this, "配置文件错误", Toast.LENGTH_SHORT).show();
//异常处理
                    }
                }


            }

            @Override
            public void Back() {
                finish();
            }

            @Override
            public void ClearOldData() {
                //清除历史搜索记录  更新记录原始数据
            }

            @Override
            public void SaveOldData(ArrayList<String> AlloldDataList) {
                //保存所有的搜索记录
            }
        });
    }


}
